package rc.work.module.infra.service.onlyoffice.officehistory;

import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import rc.work.framework.common.pojo.PageResult;
import rc.work.framework.common.util.object.BeanUtils;
import rc.work.module.infra.controller.admin.onlyoffice.officehistory.vo.OfficeHistoryPageReqVO;
import rc.work.module.infra.controller.admin.onlyoffice.officehistory.vo.OfficeHistorySaveReqVO;
import rc.work.module.infra.dal.dataobject.officehistory.OfficeHistoryDO;
import rc.work.module.infra.dal.mysql.onlyoffice.OfficeHistoryMapper;


/**
 * onlyoffice历史记录 Service 实现类
 *
 * @author 默认
 */
@Service
@Validated
public class OfficeHistoryServiceImpl implements OfficeHistoryService {

    @Resource
    private OfficeHistoryMapper officeHistoryMapper;

    @Override
    public Long createOfficeHistory(OfficeHistorySaveReqVO createReqVO) {
        // 插入
        OfficeHistoryDO officeHistory = BeanUtils.toBean(createReqVO, OfficeHistoryDO.class);
        officeHistoryMapper.insert(officeHistory);
        // 返回
        return officeHistory.getId();
    }

    @Override
    public void updateOfficeHistory(OfficeHistorySaveReqVO updateReqVO) {
        // 校验存在
//        validateOfficeHistoryExists(updateReqVO.getId());
        // 更新
        OfficeHistoryDO updateObj = BeanUtils.toBean(updateReqVO, OfficeHistoryDO.class);
        officeHistoryMapper.updateById(updateObj);
    }

    @Override
    public void deleteOfficeHistory(Long id) {
        // 校验存在
//        validateOfficeHistoryExists(id);
        // 删除
        officeHistoryMapper.deleteById(id);
    }

//    private void validateOfficeHistoryExists(Long id) {
//        if (officeHistoryMapper.selectById(id) == null) {
//            throw exception(OFFICE_HISTORY_NOT_EXISTS);
//        }
//    }

    @Override
    public OfficeHistoryDO getOfficeHistory(Long id) {
        return officeHistoryMapper.selectById(id);
    }

    @Override
    public PageResult<OfficeHistoryDO> getOfficeHistoryPage(OfficeHistoryPageReqVO pageReqVO) {
        return officeHistoryMapper.selectPage(pageReqVO);
    }

}